home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-26 | 4.8 KB | 213 lines | [TEXT/KAHL] |
-
- // to-do ... make it use RGBColor instead of indexed color
- // since all of my util routines use RGBColor
- // // //
- // ad-ized by j.t.judge
- // May 14, 1994
-
- /*
- * Rorschach's ink blot test
- *
- * Copyright (c) 1992 by Jamie Zawinski
- *
- * 2-Sep-93: xlock version (David Bagley bagleyd@source.asset.com)
- * 1992: xscreensaver version (Jamie Zawinski jwz@lucid.com)
- */
-
- /* original copyright
- * Copyright (c) 1992 by Jamie Zawinski
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation. No representations are made about the suitability of this
- * software for any purpose. It is provided "as is" without express or
- * implied warranty.
- */
-
- //#include "xlock.h"
-
- #include "blot.h"
- #include "utils.h"
-
- typedef struct {
- int width;
- int height;
- int xmid, ymid;
- int offset;
- Boolean xsym, ysym;
- int size;
- unsigned short pix; // index into the color map (which color to use)
- unsigned long startTime; // seconds
- } blotstruct;
-
-
-
- static blotstruct blots[MAXSCREENS];
-
- #if 0
- //static XPoint *pointBuffer = 0; /* pointer for XDrawPoints */
- static Point *pointBuffer = 0;
- #else
- static Point pointBuffer[ MAXPOINTS+1 ]; // 640 * 480 / 1024 = 6000 (??)
- #endif
-
- short gMaxpoints;
- short gTimeout;
- //#define TIMEOUT 30
- Boolean gXsym, gYsym;
- short gOffset;
-
- int
- initblot(int whichScreen, Rect *theRect, short screenDepth)
- {
- blotstruct *bp = &blots[whichScreen];
-
- if (whichScreen >= MAXSCREENS) // lets not tromp on memory
- return;
-
-
- bp->width = theRect->right - theRect->left;
- bp->height = theRect->bottom - theRect->top;
- bp->xmid = bp->width / 2;
- bp->ymid = bp->height / 2;
-
- bp->offset = gOffset; // 4;
- bp->xsym = gXsym; //TRUE;
- bp->ysym = gYsym; //FALSE;
- #if 0
- bp->pix = 0;
- #else
- bp->pix = RangedRdm( 0, (1<<screenDepth) );
- #endif
- if (bp->offset <= 0) bp->offset = 3;
-
- #if 0 // lets take this out - it's not like I want to use lots of memory + cpu
- // to draw large chunks of points at a time.
-
- if (batchcount >= 100 || batchcount < 1)
- batchcount = 6;
- /* Fudge the size so it takes up the whole screen */
- bp->size = batchcount * bp->width * bp->height / 1024;
-
- if (!pointBuffer)
- pointBuffer = (Point *) NewPtr(bp->size * sizeof(Point));
- if (!pointBuffer) return -1;
- #endif
- bp->size = gMaxpoints; //MAXPOINTS;
-
- ForeColor( blackColor );
- BackColor( blackColor);
- EraseRect( theRect);
- ForeColor( whiteColor );
- GetDateTime( &bp->startTime );
- }
-
- void
- drawblot(int whichScreen, Rect *theRect, short screenDepth)
- {
- int x, y;
- int k;
- Point *xp = pointBuffer;
- blotstruct *bp = &blots[whichScreen];
- unsigned long secs;
-
-
- if (whichScreen >= MAXSCREENS) // lets not tromp on memory
- return;
-
- bp->offset = gOffset; // 4;
- bp->xsym = gXsym; //TRUE;
- bp->ysym = gYsym; //FALSE;
- bp->size = gMaxpoints; //MAXPOINTS;
-
- #if 0
- if (screenDepth > 8) {
- RandomRGBWalk( &bp->pix ); // ignore bp->pix and choose any color
- } else if (screenDepth > 1) {
- SetIndexedColor( bp->pix);
- if (++bp->pix >= (1 << screenDepth) ) // 1<<screenDepth == howManyColors
- bp->pix = 0;
- bp->pix = RangedRdm( 0, (1<<screenDepth) );
- }
- #else
- if (screenDepth > 1) {
- if (!gTimeout) { // no timeout? brights and darks
- if (!(Random()%2))
- bp->pix = PickDarkIndexColor();
- else
- bp->pix = PickBrightIndexColor( );
- } else
- bp->pix = PickBrightIndexColor(); // brights only
-
- // now ... set our forecolor to that new color
- SetIndexedColor( bp->pix);
- }
- #endif
-
-
- x = bp->xmid;
- y = bp->ymid;
- k = bp->size;
-
- while (k >= 4) {
- x += ((random () % (1 + (bp->offset << 1))) - bp->offset);
- y += ((random () % (1 + (bp->offset << 1))) - bp->offset);
- k--;
- xp->h = x;
- xp->v = y;
- xp++;
- if (bp->xsym) {
- k--;
- xp->h = bp->width - x;
- xp->v = y;
- xp++;
- }
-
- if (bp->ysym) {
- k--;
- xp->h = x;
- xp->v = bp->height - y;
- xp++;
- }
- if (bp->xsym && bp->ysym) {
- k--;
- xp->h = bp->width - x;
- xp->v = bp->height - y;
- xp++;
- }
- }
-
- XDrawPoints ( theRect, pointBuffer, bp->size - k);
- if (gTimeout) {
- GetDateTime( &secs );
- if ( (short)(secs - bp->startTime) > gTimeout)
- initblot(whichScreen, theRect, screenDepth );
- }
- }
-
-
-
- // draw a set of points ....
- void
- XDrawPoints(Rect *theRect, Point *points, short how_many) {
-
- while (how_many-- > 0) {
-
- if ( (theRect->left + points[how_many].h) > theRect->right)
- continue;
- if ( (theRect->top + points[how_many].v) > theRect->bottom)
- continue;
-
- MoveTo( theRect->left + points[how_many].h,
- theRect->top + points[how_many].v );
- LineTo( theRect->left + points[how_many].h,
- theRect->top + points[how_many].v );
- }
-
- }
-
-
-
-